package com.stone.framework.batch.service;

import org.springframework.stereotype.Component;

import com.stone.framework.batch.entity.CaseAssign;
import com.stone.framework.batch.entity.CaseInfo;
import com.stone.framework.batch.entity.CaseState;
import com.stone.framework.batch.model.CaseAllocBO;
import com.stone.framework.batch.model.CaseAllocResultBO;

@Component
public class BatchedCaseService extends GenericCaseService {

    @Override
    protected CaseAllocResultBO doAllocate(CaseInfo currCaseInfo, CaseAllocBO caseAllocBo) {
        CaseInfo closedCaseInfo = this.buildClosedCaseInfo(currCaseInfo);
        CaseInfo newCaseInfo = this.buildNewCaseInfo(caseAllocBo, currCaseInfo);
        CaseState newCaseState = this.buildNewCaseState(currCaseInfo, caseAllocBo);
        CaseAssign newCaseAssign = this.buildNewCaseAssign(newCaseInfo, caseAllocBo,
            currCaseInfo == null ? CaseAssign.Type.NEW : CaseAssign.Type.STRA);
        return new CaseAllocResultBO().closedCaseInfo(closedCaseInfo).newCaseInfo(newCaseInfo)
            .newCaseState(newCaseState).newCaseAssign(newCaseAssign).build();
    }

}
